//document :https://docx.js.org/#/
const officegen = require('officegen');
const xuanze = require('../db/xuanze.js')
const fs = require('fs');
const { type } = require('os');

var docx = officegen({
    type: 'docx',
    author: 'yujia',
    title: 'doc_test_2'
});

for (var i = 1; i <= 10; i++) {
    xuanze.find({ Tno: i }, { Qes: 1,Ans1:1,Ans2:1,Ans3:1,Ans4:1 }, function (err, data) {
        if (err) {
            console.log(err);
            return;
        }
        var ques = data;
        let p0bj = new docx.createP();
        p0bj.addText(ques[0].Qes);
        p0bj.addLineBreak();
        p0bj.addText(ques[0].Ans1);
        p0bj.addLineBreak();
        p0bj.addText(ques[0].Ans2);
        p0bj.addLineBreak();
        p0bj.addText(ques[0].Ans3);
        p0bj.addLineBreak();
        p0bj.addText(ques[0].Ans4);
        p0bj.addLineBreak();
        console.log(ques[0].Qes);
    })
}

setTimeout(() => {
    var out = fs.createWriteStream('test_2.docx');
    out.on('close', () => {
        console.log('success');
    })
    docx.generate(out);
}, 3000)





